package jmine.tec.web.front.pack;

import jmine.tec.database.pack.populator.AbstractPopulatorDataSource;
import jmine.tec.database.pack.populator.PopulatorBean;
import jmine.tec.utils.collection.Mapper;
import jmine.tec.utils.collection.MapperUtils;
import jmine.tec.web.front.domain.BackOfficeRequestProperty;
import bancosys.tec.persist.dao.BaseDAO;

/**
 * Pack populator for request property
 * 
 * @author vinicius
 */
public class BackOfficeRequestPropertyDataSource extends AbstractPopulatorDataSource<BackOfficeRequestProperty> {

    private BaseDAO<BackOfficeRequestProperty> backOfficeRequestPropertyDAO;

    /**
     * {@inheritDoc}
     */
    public Iterable<PopulatorBean<BackOfficeRequestProperty>> load() {
        return MapperUtils.mapList(this.backOfficeRequestPropertyDAO.findAllOrderedByPk(),
                new Mapper<BackOfficeRequestProperty, PopulatorBean<BackOfficeRequestProperty>>() {
                    public PopulatorBean<BackOfficeRequestProperty> apply(BackOfficeRequestProperty input) {
                        return new PopulatorBean<BackOfficeRequestProperty>(input, "front", "property", input.getMnemonic().toLowerCase()
                                + ".xml");
                    }
                });
    }

    /**
     * @param backOfficeRequestPropertyDAO the backOfficeRequestPropertyDAO to set
     */
    public void setBackOfficeRequestPropertyDAO(BaseDAO<BackOfficeRequestProperty> backOfficeRequestPropertyDAO) {
        this.backOfficeRequestPropertyDAO = backOfficeRequestPropertyDAO;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "PropertiesPopulatorDataSource";
    }

}
